#include "main.h"
#include "Vect3D.h"
//#include "Polygone.h"
//#include "PolyOp.h"
#include "Render.h"
#include "EventManager.h"
#include "VertexMan.h"
#include "tools.h"
#include "TEST.h"

#include <ctime>
#include <sstream>

using namespace std;
using namespace me;
using namespace tls;

void mainAurore();
//void loopSDL();

void mainJohan();
//void tests();
//void testSdl();

string compiledBy;

int main(int argc, char** argv) {
	cout << "param listing" << endl;
	for (int i = 0; i < argc; ++i) {
		cout << "arg[" << i << "]:" << argv[i] << endl;
	}
	// initialisation du generateur de random
	srand(time(NULL));

#ifdef JCOMP
	compiledBy = "Jo";

	mainJohan();

#endif

#ifdef ACOMP
	compiledBy="Aurore";
	me::VertexMan::memoryAvailable();
	mainAurore();
#endif

	cout << "Fin OK" << endl;
	return 0;
}

void mainJohan() {
	cout << "main de jo" << endl;
	TEST::all();
	cout << "fin de main de jojo." << endl;
}


void mainAurore() {
	// print debug mode
	cout << "DEBUGMODE " << DEBUGMODE << endl;
//	loopSDL();
}

/*

void testSdl() {
	SDL_Surface* screen;

	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		printf("Unable to init SDL: %s\n", SDL_GetError());
		exit(0);
	}
//	// make sure SDL cleans up before exit
//	atexit(SDL_Quit);
	//
	//	freopen( "CON", "wt", stdout );
	//	freopen( "CON", "wt", stderr );

	// create a new window
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	int W = 800, H = 600, frame = 0, BPP = 32;
	int FLAG = SDL_OPENGL | SDL_FULLSCREEN * 0; //SDL_FULLSCREEN: perf x10 !!!!!

	// titre de la fenetre
	stringstream a;
	a << "worms | v0.0 | " << __DATE__ << "@" << __TIME__ << " | " << compiledBy;
	SDL_WM_SetCaption(a.str().c_str(), NULL);

	screen = SDL_SetVideoMode(W, H, BPP, FLAG);

	//    SDL_Surface* texture = SDL_CreateRGBSurface(FLAG,INTILESIZE,INTILESIZE, BPP, FLAG);
	if (!screen) {
		printf("Unable to set this video mode: %s\n", SDL_GetError());
		exit(0);
	}
	cout << "l:" << __LINE__ << ":video mode set OK" << endl;

	Render::GLini();
	Render render;

	EventManager eventManager;
	bool done = false;
	//limit fps
	Uint32 start, end;
	const int FRAMES_PER_SECONDS = 50; //todo class de config. On y regle le fps cible, et d'autre merdier.

	while (!done) {
		cout << "frame " << frame++ << endl;
		start = SDL_GetTicks();

		render.majScreen(800, 600);
		render.majCamera();

		// window.clear();
		//window.draw(text);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the screen and depth buffer

		//		render.test(depht);
		for (Polygone* po : toDraw) {
			po->draw(WIRE);
		}
		//        initGL();
		eventManager.manage(done, render);
		//

		//		glFlush();
		SDL_GL_SwapBuffers();

		end = SDL_GetTicks();
		if ((end - start) < (1.f / FRAMES_PER_SECONDS) * 1000)
			SDL_Delay((1.f / FRAMES_PER_SECONDS) * 1000 - (end - start));
		cout << "frame ms:" << end - start << endl;
	}

	SDL_Quit();
}

*/
/*
void loopSDL() {

	SDL_Surface* screen;

	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		printf("Unable to init SDL: %s\n", SDL_GetError());
		exit(0);
	}

	// create a new window
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	int W = 800, H = 600, frame = 0, BPP = 32;
	int FLAG = SDL_OPENGL | SDL_FULLSCREEN * 0;

	// titre de la fenetre
	stringstream b;
	b << "worms | v0.0 | " << __DATE__ << "@" << __TIME__ << " | " << compiledBy;
	SDL_WM_SetCaption(b.str().c_str(), NULL);

	screen = SDL_SetVideoMode(W, H, BPP, FLAG);

	//    SDL_Surface* texture = SDL_CreateRGBSurface(FLAG,INTILESIZE,INTILESIZE, BPP, FLAG);
	if (!screen) {
		printf("Unable to set this video mode: %s\n", SDL_GetError());
		exit(0);
	}
	cout << "l:" << __LINE__ << ":video mode set OK" << endl;

	Render::GLini();
	Render render;

	EventManager eventManager;
	bool done = false;
	//limit fps
	Uint32 start, end;
	const int FRAMES_PER_SECONDS = 50;

	render.majScreen(800, 600);

	while (!done) {
		cout << "frame " << frame++ << endl;
		start = SDL_GetTicks();

		render.majCamera();
		render.majScreen(800, 600);

		// window.clear();
		//window.draw(text);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the screen and depth buffer

		render.test(0);

		eventManager.manage(done, render);
		//

		//		glFlush();
		SDL_GL_SwapBuffers();

		end = SDL_GetTicks();
		if ((end - start) < (1.f / FRAMES_PER_SECONDS) * 1000)
			SDL_Delay((1.f / FRAMES_PER_SECONDS) * 1000 - (end - start));
		cout << "frame ms:" << end - start << endl;
	}

	SDL_Quit();
}

*/
